package com.example.user.coolrun.runnershign;

//import android.content.Context;
//import android.content.Intent;
//import android.support.v7.widget.CardView;
//import android.support.v7.widget.RecyclerView;
//import android.view.LayoutInflater;
//import android.view.View;
//import android.view.ViewGroup;
//import android.widget.ImageView;
//import android.widget.TextView;
//
//import com.example.user.coolrun.R;
//
//import java.util.List;
//
//public class PeopleAdapter extends RecyclerView.Adapter<PeopleAdapter.ViewHolder>
//{
//    private Context mcontext;
//    private List<People> mPeopleList;
//
//    static class ViewHolder extends RecyclerView.ViewHolder{
//        CardView cardView;
//        ImageView peopleImage;
//        TextView peopleName;
//
//        public ViewHolder(View view){
//            super(view);
//            cardView = (CardView) view;
//            peopleImage = (ImageView)view.findViewById(R.id.people_image);
//            peopleName = (TextView)view.findViewById(R.id.people_name);
//        }
//    }
//
//    public PeopleAdapter(List<People> peopleList){
//        mPeopleList = peopleList;
//    }
//
//    @Override
//    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType){
//        if (mcontext == null){
//            mcontext = parent.getContext();
//        }
//        View view = LayoutInflater.from(mcontext).inflate(R.layout.people_item, parent, false);
//        final ViewHolder holder = new ViewHolder(view);
//        holder.cardView.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View v) {
//                int position = holder.getAdapterPosition();
//                People people = mPeopleList.get(position);
//                Intent intent = new Intent(mcontext, PeopleActivity.class);
//                intent.putExtra(PeopleActivity.PEOPLE_NAME, people.getName());
//                intent.putExtra(PeopleActivity.PEOPLE_IMAGE_ID, people.getImageId());
//                mcontext.startActivity(intent);
//            }
//        });
//        return holder;
//
//    }
//
//    @Override
//    public void onBindViewHolder(ViewHolder holder, int position){
//        People people = mPeopleList.get(position);
//        holder.peopleImage.setImageResource(people.getImageId());
//        holder.peopleName.setText(people.getName());
//    }
//
//    @Override
//    public int getItemCount(){
//        return mPeopleList.size();
//    }

//}
import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.CardView;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.example.user.coolrun.R;

import org.w3c.dom.Text;

import java.util.List;
import java.util.Stack;

public class PeopleAdapter extends RecyclerView.Adapter<PeopleAdapter.ViewHolder>
{
    private Context mcontext;
    private List<People> mPeopleList;

    static class ViewHolder extends RecyclerView.ViewHolder{
        CardView cardView;
        ImageView peopleImage;
        TextView peopleName;

        public ViewHolder(View view){
            super(view);
            cardView = (CardView) view;
            peopleImage = (ImageView)view.findViewById(R.id.people_image);
            peopleName = (TextView)view.findViewById(R.id.people_name);
        }
    }

    public PeopleAdapter(List<People> peopleList){
        mPeopleList = peopleList;
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType){
        if (mcontext == null){
            mcontext = parent.getContext();
        }
        View view = LayoutInflater.from(mcontext).inflate(
                R.layout.people_item, parent, false);
        final ViewHolder holder = new ViewHolder(view);
        holder.cardView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                int position = holder.getAdapterPosition();
                People people = mPeopleList.get(position);
                Intent intent = new Intent(mcontext, PeopleActivity.class);
                intent.putExtra(PeopleActivity.PEOPLE_NAME, people.getName());
                intent.putExtra(PeopleActivity.PEOPLE_IMAGE_ID, people.getImageId());
                mcontext.startActivity(intent);
            }
        });
        return holder;
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, int position){
        People people = mPeopleList.get(position);
        holder.peopleImage.setImageResource(people.getImageId());
        holder.peopleName.setText(people.getName());
    }

    @Override
    public int getItemCount(){
        return mPeopleList.size();
    }

}